<?php if ( ! defined('BASEPATH')) exit('This file does not run directly. Sorry.'); ?>
<?php
/**
 * Kalaisoo.
 *
 * A lightweight no-framework framework written in PHP.
 *
 * @package Kalaisoo
 * @author $Author: info@sah-company.com $
 */
?>
<!-- Blogposts -->
<?php
/**
 * If there are records each one is displayed.
 * If there are at least as many records as the maximum count of records per load,
 * a link id displayed allowing to load the next records in the table.
 * See the template that incorporates this on for the javascript which
 * triggers the loading of next record sets when scrolling to the end of the page.
 */
if ( is_array($records['blog']) && ! empty($records['blog'])):
	foreach ($records['blog'] as $n=>$record):
		$author = R::dispense('user');
		$authors = R::related($record, 'user');
		if ( ! empty($authors)) $author = array_shift($authors);
		if ( ! $record->location) $record->location = __('unknown_location');
?>
<article id="record-<?php echo $record->id; ?>" class="item<?php echo ($record->auto) ? ' auto' : ' triangle-border top'; ?>">
	
	<header>
		<h1><?php echo __('blog'),' ',$record->getId(); ?></h1>
		<p>
			<span
				class="date">
				<?php echo strftime($locale['date_format'], $record->stamp); ?>
			</span>
			<span
				class="hour">
				<?php echo strftime($locale['time_format'], $record->stamp); ?>
			</span>
		</p>
		<p class="location"><?php echo sprintf(__('nearby_location'), ahref(sprintf('{language}/user/profile/%s', $author->getId())), htmlspecialchars($author->name()), htmlspecialchars($record->location)); ?></p>
	</header>
	
	<section>
		<?php echo textile($record->content),"\n"; ?>
	</section>

</article>

<?php
	endforeach;
?>
<!-- /Blogposts -->
<!-- Link to load more blogposts -->
<?php
	/**
	 * There are at least as many records in this block than the limit, so we display
	 * the link which gets triggered on scrolling to/past the end of the document.
	 */
	if (isset($records['limitFind']) && count($records['blog']) >= $records['limitFind']):
?>
<a
	id="loadOnScroll"
	class="action loadonscroll"
	data-target="response"
	href="<?php echo ahref(sprintf('%s/user/index/%d/%d', $language, $records['limitOffset'] + $records['limitFind'], $records['limitFind'])); ?>">
	<?php echo __('continue'); ?>
</a>
<?php
	endif;
?>
<!-- /Link -->
<?php
endif;
?>